﻿@using System.Diagnostics
@using Masuit.MyBlogs.Core.Common
@using Masuit.MyBlogs.Core.Models.DTO
@model Masuit.MyBlogs.Core.Models.ViewModel.HomePageViewModel
@{
    string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
}
<aside class="col-md-3 box-right">
    @if (Model.Notices.Any())
    {
        <section class="wow animated fadeIn">
            <article class="panel panel-info">
                <div class="panel-heading">
                    <i class="icon-clipboard2"></i><span>近期公告</span>
                    <a class="pull-right text-success" asp-controller="Notice" asp-action="Index">所有公告</a>
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-xs-12">
                            <ul class="notices">
                                @foreach (NoticeDto notice in Model.Notices)
                                {
                                    <li class="news-item">
                                        <a asp-controller="Notice" asp-action="Details" asp-route-id="@notice.Id">@await notice.Content.GetSummary(45, 2)</a>
                                    </li>
                                }
                            </ul>
                        </div>
                    </div>
                </div>
            </article>
        </section>
    }
    <section class="wow animated fadeIn">
        <article class="panel panel-info">
            <div class="panel-heading">
                <i class="icon-lab2"></i>文章分类
                <a asp-controller="Post" asp-action="All" class="pull-right text-success">所有分类</a>
            </div>
            <div class="panel-body">
                <ul class="list-group">
                    @foreach (var cat in Model.Categories.Where(c => c.PendedPostCount > 0))
                    {
                    <li class="list-group-item">
                        <a asp-controller="Home" asp-action="Category" asp-route-id="@cat.Id">@cat.Name</a>
                        <a class="pull-right" asp-controller="Subscribe" asp-action="CategoryRss" asp-route-id="@cat.Id" target="_blank">
                            <i class="icon-rss4"></i>
                        </a>
                    </li>
                    }
                </ul>
            </div>
        </article>
    </section>
    @foreach (var ad in Model.SidebarAds)
    {
        <section>
            <article class="panel panel-info">
                <div class="panel-heading">
                    @ad.Title
                </div>
                <div class="panel-body" id="@Stopwatch.GetTimestamp()">
                    <a asp-controller="Advertisement" asp-action="Redirect" asp-route-id="@ad.Id" target="_blank" id="@Stopwatch.GetTimestamp()">
                        <img class="img img-responsive" src="@ad.ThumbImgUrl" alt="@ad.Title" title="@ad.Title" />
                    </a>
                </div>
            </article>
        </section>
    }

    <section class="wow animated fadeIn">
        <div class="leaderboard-box">
            <div class="leaderboard">
                <h2>推荐文章</h2>
                <ol>
                    @foreach (PostDto post in Model.Top5Post)
                    {
                        <li>
                            <a asp-controller="Post" asp-action="Details" asp-route-id="@post.Id">
                                <mark>@(post.Title.Length >= 20 ? post.Title.Substring(0, 20) + "..." : post.Title) </mark>
                                <small style="color:#00ffff"> @post.TotalViewCount</small>
                            </a>
                        </li>
                    }
                </ol>
            </div>
            <svg style="display: none;">
                <symbol id="cup" x="0px" y="0px" width="25px" height="26px" viewBox="0 0 25 26" enable-background="new 0 0 25 26" xml:space="preserve">
                <path fill="#F26856" d="M21.215,1.428c-0.744,0-1.438,0.213-2.024,0.579V0.865c0-0.478-0.394-0.865-0.88-0.865H6.69
				C6.204,0,5.81,0.387,5.81,0.865v1.142C5.224,1.641,4.53,1.428,3.785,1.428C1.698,1.428,0,3.097,0,5.148
				C0,7.2,1.698,8.869,3.785,8.869h1.453c0.315,0,0.572,0.252,0.572,0.562c0,0.311-0.257,0.563-0.572,0.563
				c-0.486,0-0.88,0.388-0.88,0.865c0,0.478,0.395,0.865,0.88,0.865c0.421,0,0.816-0.111,1.158-0.303
				c0.318,0.865,0.761,1.647,1.318,2.31c0.686,0.814,1.515,1.425,2.433,1.808c-0.04,0.487-0.154,1.349-0.481,2.191
				c-0.591,1.519-1.564,2.257-2.975,2.257H5.238c-0.486,0-0.88,0.388-0.88,0.865v4.283c0,0.478,0.395,0.865,0.88,0.865h14.525
				c0.485,0,0.88-0.388,0.88-0.865v-4.283c0-0.478-0.395-0.865-0.88-0.865h-1.452c-1.411,0-2.385-0.738-2.975-2.257
				c-0.328-0.843-0.441-1.704-0.482-2.191c0.918-0.383,1.748-0.993,2.434-1.808c0.557-0.663,1-1.445,1.318-2.31
				c0.342,0.192,0.736,0.303,1.157,0.303c0.486,0,0.88-0.387,0.88-0.865c0-0.478-0.394-0.865-0.88-0.865
				c-0.315,0-0.572-0.252-0.572-0.563c0-0.31,0.257-0.562,0.572-0.562h1.452C23.303,8.869,25,7.2,25,5.148
				C25,3.097,23.303,1.428,21.215,1.428z M5.238,7.138H3.785c-1.116,0-2.024-0.893-2.024-1.99c0-1.097,0.908-1.99,2.024-1.99
				c1.117,0,2.025,0.893,2.025,1.99v2.06C5.627,7.163,5.435,7.138,5.238,7.138z M18.883,21.717v2.553H6.118v-2.553H18.883
				L18.883,21.717z M13.673,18.301c0.248,0.65,0.566,1.214,0.947,1.686h-4.24c0.381-0.472,0.699-1.035,0.947-1.686
				c0.33-0.865,0.479-1.723,0.545-2.327c0.207,0.021,0.416,0.033,0.627,0.033c0.211,0,0.42-0.013,0.627-0.033
				C13.195,16.578,13.344,17.436,13.673,18.301z M12.5,14.276c-2.856,0-4.93-2.638-4.93-6.273V1.73h9.859v6.273
				C17.43,11.638,15.357,14.276,12.5,14.276z M21.215,7.138h-1.452c-0.197,0-0.39,0.024-0.572,0.07v-2.06
				c0-1.097,0.908-1.99,2.024-1.99c1.117,0,2.025,0.893,2.025,1.99C23.241,6.246,22.333,7.138,21.215,7.138z" /></symbol>
            </svg>
        </div>
    </section>
    <section class="wow animated fadeIn">
        <article class="panel panel-info">
            <div class="panel-heading">
                <i class="icon-lightbulb"></i>标签云 <a asp-controller="Post" asp-action="All" class="pull-right text-success">所有标签</a>
            </div>
            <div class="panel-body text-center">
                <div id="tagscloud">
                    @if (Model.Tags.Any())
                    {
                        foreach (var (key, value) in Model.Tags)
                        {
                            <a asp-controller="Home" asp-action="Tag" asp-route-tag="@key" class="tagc-@(new Random().Next(100) % 10)" style="font-size: @(value)px; line-height: @(value * 1.2)px;">@key</a>
                        }
                    }
                    else
                    {
                        <a class="tagc-@(new Random().Next(100) % 10)">没有标签</a>
                    }
                </div>
            </div>
        </article>
    </section>

    <section class="wow animated fadeIn">
        <article class="panel panel-info">
            <div class="panel-heading">
                <i class="icon-fire"></i>近期热搜 Top10
            </div>
            <div class="panel-body text-center line-height24">
                @foreach (var s in Model.HotSearch)
                {
                    <a asp-controller="Search" asp-action="Search" asp-route-wd="@s.Keywords">
                        @if (s.Keywords.Length > 15)
                        {
                            <span class="label label-@colors[s.Count % colors.Length]">@s.Keywords.Substring(0, 15)... (@s.Count)</span>
                        }
                        else
                        {
                            <span class="label label-@colors[s.Count % colors.Length]">@s.Keywords (@s.Count)</span>
                        }
                    </a>
                }
            </div>
        </article>
    </section>
</aside>